﻿Public Class TorqueForm

    Private Sensor As TorqueSensor
    Private Graph As MaGraph

    Private Sub TorqueForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        '160E 测试台用0,1通道
        '100C 新试台用2,3通道
        Sensor = New TorqueSensor(start_ch:=0) With {
            .QueueLength = 500
        }
        Graph = New MaGraph(Zed)
        Graph.SetTitle("传感器数据")
    End Sub

    Private Sub BtnBegin_Click(sender As Object, e As EventArgs) Handles BtnBegin.Click
        Sensor.SetRatio(20, 300)
        Sensor.Begin()
        TmGraph.Start()
    End Sub

    '绘制曲线
    Private Sub TmGraph_Tick(sender As Object, e As EventArgs) Handles TmGraph.Tick

        Sensor.PushData()

        Debug.Print($"Time: {Sensor.GetTimeBuf().Last()}, Master: {Sensor.Master}, Load: {Sensor.Load}")

        Graph.ClearCurve()
        Graph.AddCurve("Master", Sensor.GetTimeBuf(), Sensor.GetMasterBuf(), Color.Blue)
        Graph.AddCurve("Load", Sensor.GetTimeBuf(), Sensor.GetLoadBuf(), Color.Red)
        Graph.RefreshCurve()

        lbCnt0.Text = Sensor.MasterCount
        lbCnt1.Text = Sensor.LoadCount

    End Sub

    Private Sub BtnStop_Click(sender As Object, e As EventArgs) Handles BtnStop.Click
        'TmGraph.Stop()
        'Sensor.Stop()
        Sensor.Restart()
    End Sub
End Class